﻿using System;
using System.Configuration;
using System.Web;

namespace Shuba.Web.master
{
    public partial class holiday_approval : basePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string acl = GetUserAccess("MSTR_HOLIDAY");

                if (!IsUserChecker(acl))
                {
                    string msg = this.GetGlobalResourceObject("Messages", "NoPrivilege").ToString();
                    AlertAndRedirect(msg, ResolveUrl(ConfigurationManager.AppSettings["default_url"]));
                }

                LabelTitle.Text = GetPageTitle("MSTR_HOLIDAY");

                hidHolidayDate.Value = Request.QueryString["id"];

                Shuba.Business.Holiday bl = new Shuba.Business.Holiday();
                Shuba.Model.HolidayInfo bi;

                bi = bl.GetApprovalByID(Convert.ToDateTime(hidHolidayDate.Value));
                txtHolidayDate.Text = bi.HOLIDAY_DATE.ToString();
                txtHolidayName.Text = bi.HOLIDAY_NAME;
                lblActType.Text = bi.ACT_TYPE;
                lblActDate.Text = bi.ENTRY_DATE.ToString("dd MMM yyyy hh:mm:ss");
                lblUpdateBy.Text = bi.ENTRY_BY;

                if (IsUserAdd(acl))
                {
                    btnAdd.Enabled = true;
                    btnUpload.Enabled = true;
                }
                else
                {
                    btnAdd.Enabled = false;
                    btnUpload.Enabled = false;
                }
            }
        }

        protected void btnApprove_Click(object sender, EventArgs e)
        {
            string msg = "";
            string ActType = lblActType.Text;
            string IsApprove = ddlApprove.SelectedItem.Value;
            string id = hidHolidayDate.Value;

            Shuba.Business.Holiday bl = new Shuba.Business.Holiday();
            Shuba.Model.HolidayInfo bi = new Shuba.Model.HolidayInfo();

            bi = bl.GetApprovalByID(Convert.ToDateTime(id));
            bi.UPDATE_BY = HttpContext.Current.User.Identity.Name;
            bi.UPDATE_DATE = ProcessingDate();

            if (IsApprove == "1")
            {
                bl.Approve(Convert.ToDateTime(id), ActType);
                AddLog("APPROVAL", "APPROVE HOLIDAY");
                msg = this.GetGlobalResourceObject("Messages", "ApproveAlert").ToString();
            }
            else
            {
                bl.Reject(Convert.ToDateTime(id));
                AddLog("APPROVAL", "REJECT HOLIDAY");
                msg = this.GetGlobalResourceObject("Messages", "NoApprove").ToString();
            }

            AlertAndRedirect(msg, "holiday_list.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("holiday_list.aspx");
        }
    }
}
